﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BLL;
using DAL.Linq.EntityMapper;

namespace DAL.Linq
{
    public class LinqDMHANGHOA_Dao : IDMHANGHOA_Dao
    {
        #region IDao<DMHANGHOAInfo,string> Members

        /// <summary>
        /// Gets a list of all DMHANGHOAs.
        /// </summary>
        /// <returns>List of DMHANGHOAs.</returns>
        public IList<DMHANGHOA> GetAll()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Gets a specific DMHANGHOA.
        /// </summary>
        /// <param name="maHangHoa">Unique MaHangHoa identifier.</param>
        /// <returns>DMHANGHOA.</returns>
        public DMHANGHOA GetById(string maHangHoa)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IDMHANGHOA_Dao Members

        public bool DMHangHoa_Insert(string MaHangHoa, string TenHangHoa, int MaDonViTinh, decimal DonGia, bool IsUse, int CreateBy)
        {
            int bln = 0;
            using (Invoice db = DataContextFactory.CreateContext())
            {
                try
                {
                    bln = db.sp_DMHangHoa_Insert(MaHangHoa, TenHangHoa, MaDonViTinh, DonGia, IsUse, CreateBy);
                    if (bln == 1)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                catch { return false; }
            }
        }

        public bool DMHangHoa_Update(string MaHangHoa, string TenHangHoa, int MaDonViTinh, decimal DonGia, bool IsUse,  int ModifiedBy, DateTime ModifiedOn)
        {
            int bln = 0;
            using (Invoice db = DataContextFactory.CreateContext())
            {
                try
                {
                    bln = db.sp_DMHangHoa_Update(MaHangHoa, TenHangHoa, MaDonViTinh, DonGia, IsUse, ModifiedBy, ModifiedOn);
                    if (bln == 1)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                catch { return false; }
            }
        }

        public bool DMHangHoa_Delete(string MaHangHoa)
        {
            int bln = 0;
            using (Invoice db = DataContextFactory.CreateContext())
            {
                try
                {
                    bln = db.sp_DMHangHoa_Delete(MaHangHoa);
                    if (bln == 1)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                catch { return false; }
            }
        }

        public IList<DMHANGHOA> GetAll_DMHangHoa()
        {
            List<DMHANGHOA> lst = null;
            using (Invoice db = DataContextFactory.CreateContext())
            {
                try
                {
                    lst = db.sp_DMHangHoa_GetAll().Select(p => Mapper.ToBusinessObject(p)).ToList();
                }
                catch { }
                finally
                {
                    if (db != null)
                        db.Dispose();
                }
            }
            return lst;
        }

        #endregion
    }
}
